package com.jctrip.hotel.management.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.jctrip.hotel.management.model.param.*;
import com.jctrip.hotel.management.model.param.InsertSourceInfoParam;
import com.jctrip.hotel.management.model.param.RemoveSourceInfoParam;
import com.jctrip.hotel.management.model.param.UpdateSourceInfoParam;
import com.jctrip.hotel.management.model.result.*;
import com.jctrip.hotel.management.service.SourceInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(tags = "management-source")
@RestController
@RequestMapping("/management/source")
public class SourceInfoController {
    @Autowired
    private SourceInfoService sourceInfoService;

    @GetMapping("/listSourceCode")
    @ApiOperation(value = "listSourceCode", notes = "获取供应编码列表")
    @ApiOperationSupport(order = 1)
    public Result<GetSourceCodeResult> listSourceCode() { return Result.ok(sourceInfoService.listCodeName());}

    @PostMapping("/listName")
    @ApiOperation(value = "listName", notes = "获取供应列表")
    @ApiOperationSupport(order = 2)
    public Result<GetSourceNameResult> listName(GetSourceNameParam param){
        return Result.ok(sourceInfoService.listName(param));
    }

    @PostMapping("/listSourceNames")
    public Result<GetSourceNameResult> listSourceNames(@RequestBody GetSourceNameParam param){
        return Result.ok(sourceInfoService.listName(param));
    }

    @PostMapping("/listHotels")
    @ApiOperation(value = "listHotels", notes = "展示供应对应的酒店")
    @ApiOperationSupport(order = 3)
    public Result<GetSourceHotelsResult> listHotels(@RequestBody GetSourceHotelsParam param){
        return Result.ok(sourceInfoService.listHotels(param));
    }

    @GetMapping("/list")
    @ApiOperation(value = "list", notes = "展示所有的供应信息")
    @ApiOperationSupport(order = 4)
    public Result<GetAllSourceListResult> listAllSources(@RequestParam(value = "source_code", required = false)String sourceCode,
                                                         @RequestParam(value = "name", required = false)String name,
                                                         @RequestParam(value = "pageNo", required = false, defaultValue = "1")Long pageNo,
                                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10")Long pageSize){
        return Result.ok(sourceInfoService.listAllSources(sourceCode, name, pageNo, pageSize));
    }

    @GetMapping("/listAll")
    @ApiOperation(value = "listAll", notes = "所有供应")
    @ApiOperationSupport(order = 5)
    public Result<List<GetAllSourceListResult.SourceInfo>> listAll(){
        return Result.ok(sourceInfoService.listAll());
    }

    @PostMapping("/edit")
    @ApiOperation(value = "edit", notes = "修改供应信息")
    @ApiOperationSupport(order = 6)
    public Result<String> editSourceInfo(@RequestBody UpdateSourceInfoParam param){
        return Result.ok(sourceInfoService.editSourceInfo(param));
    }

    @PostMapping("/add")
    @ApiOperation(value = "add", notes = "添加供应信息")
    @ApiOperationSupport(order = 7)
    public Result<String> addSourceInfo(@RequestBody InsertSourceInfoParam param){
        return Result.ok(sourceInfoService.addSourceInfo(param));
    }

    @PostMapping("/delete")
    @ApiOperation(value = "delete", notes = "删除供应信息")
    @ApiOperationSupport(order = 8)
    public Result<String> deleteSourceInfo(@RequestBody RemoveSourceInfoParam param){
        return Result.ok(sourceInfoService.deleteSourceInfo(param));
    }
}
